package com.liuxvru.project.user.controller;

import com.liuxvru.common.annotation.Log;
import com.liuxvru.common.core.controller.BaseController;
import com.liuxvru.common.core.domain.AjaxResult;
import com.liuxvru.common.core.page.TableDataInfo;
import com.liuxvru.common.enums.BusinessType;
import com.liuxvru.project.domain.Project;
import com.liuxvru.project.service.IProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/project")
public class UserProjectsController extends BaseController {
    @Autowired
    private IProjectService projectService;

    /**
     * 查询
     */
    @GetMapping("/list")
    public TableDataInfo list(Project projects) {
        startPage();
        List<Project> list = projectService.selectProjectList(projects);
        return this.getDataTable(list);
    }

    /**
     * 查询
     */
    @GetMapping("/listAll")
    public AjaxResult listAll(Project projects) {
        List<Project> list = projectService.selectProjectList(projects);
        return success(list);
    }

    @GetMapping("/{projectId}")
    public AjaxResult getProjectById(@PathVariable("projectId") String projectId) {
        Project byId = projectService.getById(projectId);
        return this.success(byId);
    }

    @PostMapping("/createProject")
    public AjaxResult createProject(@RequestBody Project projects) {
        return toAjax(projectService.createProject(projects));
    }

    /**
     * 修改项目
     */
    @PreAuthorize("@ss.hasPermi('project:project:edit')")
    @Log(title = "项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Project project) {
        return toAjax(projectService.edit(project));
    }

}
